﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aribaccio.Device
{
    /// <summary>
    /// 设备串行接口
    /// </summary>
    /// <typeparam name="TPara">设备串行连接参数接口</typeparam>
    public interface IDeviceSerial<TPara> : IDevice<TPara> where TPara : IDevicePara
    {
        /// <summary>
        /// 串行端口资源对象
        /// </summary>
        SerialPort DeviceSerialPort { get; set; }
        /// <summary>
        /// 串口读取超时时间
        /// </summary>
        int DefaultReadTimeout { get; set; }
        /// <summary>
        /// 串口写入超时时间
        /// </summary>
        int DefaultWriteTimeout { get; set; }
        /// <summary>
        /// 睡眠的时间
        /// </summary>
        int SleepTime { get; set; }
        /// <summary>
        /// 接收数据的超时时间/毫秒
        /// </summary>
        int ReceiveTimeout { get; set; }
        /// <summary>
        /// 接收数据的超时次数
        /// </summary>
        int ReceiveTimeoutNum { get; set; }

        /// <summary>
        /// 写串行端口数据
        /// </summary>
        /// <param name="argSerialPortData">串行端口数据</param>
        Result SendSerialPortData(byte[] argSerialPortData);

        /// <summary>
        /// 写串行端口数据
        /// </summary>
        /// <param name="argSerialPortData">串行端口数据</param>
        /// <param name="argIsEnter">是否多加换行符</param>
        Result SendSerialPortData(string argSerialPortData, bool argIsEnter = true);

        /// <summary>
        /// 从串口接收数据信息
        /// </summary>
        /// <param name="argAwaitData">是否必须要等待数据返回</param>
        /// <returns>带接收字节的结果对象</returns>
        ResultModel<byte[]> RreadSerialPortData(bool argAwaitData);

        /// <summary>
        /// 从串口接收数据信息-只适应校验和方式
        /// </summary>
        /// <param name="argSlaveAddress">起始或头</param>
        /// <param name="argStopBit">包尾停止</param>
        /// <param name="argDataLength">数据长度</param>
        /// <returns>带接收字节的结果对象</returns>
        ResultModel<byte[]> RreadSerialPortData(byte argSlaveAddress, byte argStopBit, byte argDataLength);
    }
}
